/*
 * @# AlbumsLikesController.java 2011-12-30 下午03:46:10
 * 
 * Copyright (C) 2010 - 2011 广州羿安信息科技有限公司
 * Guangzhou ianswer information technology co. ltd.
 * 
 * All rights reserved!
 */
package com.ianswer.px.album.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ianswer.common.util.Feedback;
import com.ianswer.px.album.entity.AlbumLike;
import com.ianswer.px.album.service.AlbumLikeService;
import com.ianswer.px.common.SessionContextHolder;
import com.ianswer.px.common.annotation.SessionAware;

/**
 * @author alvin hwang
 */
@SessionAware
@Controller
public class AlbumsLikesController {

	@Resource(name = "albumLikeService")
	private AlbumLikeService albumLikeService;
	
	@RequestMapping(value = "/albums/{albumId}/likes", method = RequestMethod.GET)
	public @ResponseBody List<AlbumLike> likes(@PathVariable("albumId") Long albumId) {
		return albumLikeService.queryFirstPage(albumId);
	}
	
	@RequestMapping(value = "/albums/{albumId}/likes/create", method = RequestMethod.POST)
	public @ResponseBody Feedback createLikes(@PathVariable("albumId") Long albumId) {
		Long userId = SessionContextHolder.getUserId();
		albumLikeService.insert(albumId, userId);
		return Feedback.success("t");
	}
}
